package com.lw.extraceim.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lw.extraceim.R;
import com.lw.extraceim.model.TransPackage;

import java.util.List;
/**
 * @Author : liwei
 * @Email : 1759840027@qq.com
 * @Description :转运包裹的适配器
 * @Date : 2019/4/19 21:10
 */
public class TransPackageAdapter extends BaseAdapter {
    private List<TransPackage> transPackages;
    private Context mContext;

    public TransPackageAdapter(List<TransPackage> transPackages, Context context) {
        this.transPackages = transPackages;
        this.mContext = context;
    }

    public List<TransPackage> getTransPackages() {
        return transPackages;
    }

    public void setTransPackages(List<TransPackage> transPackages) {
        this.transPackages = transPackages;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if(transPackages != null){
            return transPackages.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = LayoutInflater.from(mContext);
        ViewHolder holder = null;
        if(convertView == null){
            convertView = inflater.inflate(R.layout.trans_package_item,null);
            holder = new ViewHolder();
            holder.mTvTransPackageId = convertView.findViewById(R.id.tv_package_id);
            holder.mTvTransPackageStatus = convertView.findViewById(R.id.tv_package_status);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        TransPackage transPackage = transPackages.get(position);
        holder.mTvTransPackageId.setText(transPackage.getId());
        holder.mTvTransPackageStatus.setText(transPackage.getStatusString());
        return convertView;
    }


    public class ViewHolder{
        public TextView mTvTransPackageId;
        public TextView mTvTransPackageStatus;
    }
}
